<?php

namespace App\Http\Controllers\WorkOrder\Wap;

use App\Http\Controllers\BaseController;
use App\Http\Validate\WorkOrder\Apply\ApplyValidate;
use App\Service\WorkOrder\Mission\MissionNoticeService;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class MissionController extends BaseController
{

    /**
     * @param string $workOrderNo
     * @return JsonResponse
     * @throws GuzzleException
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function pressNotice(string $workOrderNo): JsonResponse
    {
        ApplyValidate::pressNoticeValidate(["workOrderNo" => $workOrderNo]);
        MissionNoticeService::pressNotice($workOrderNo);
        return $this->success();
    }

    /**
     * @param Request $request
     * @param string $workOrderNo
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException|GuzzleException
     */
    public function missionNotice(Request $request, string $workOrderNo): JsonResponse
    {
        $params = ApplyValidate::missionNoticeValidate($request->merge(["workOrderNo" => $workOrderNo])->all());
        MissionNoticeService::missionNotice($params->id, $workOrderNo);
        return $this->success();
    }

}
